/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package topcoder;

import java.util.HashMap;

/**
 *
 * @author Mohamed.Azouz
 */
public class ContestWinner {

    public int getWinner(int[] events) {
        HashMap<Integer, Integer> users = new HashMap<Integer, Integer>();
        int maxCon = events[0];
        int max = -1;
        for (int i = 0; i < events.length; i++) {
            int event = events[i];
            int num = 0;
            if (users.containsKey(event)) {
                num = users.get(event) + 1;
            } else {
                num = 1;
            }
            users.put(event, num);
            if (num > max) {
                maxCon = event;
                max = num;
            }
        }
        return maxCon;
    }

    public static void main(String[] args) {
        ContestWinner contestWinner = new ContestWinner();
        int[] arr ={1,2,2,3,3,3,4,4,4,4};
        System.out.println(contestWinner.getWinner(arr));
    }
}
